<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" 
CodeFile="Daily.aspx.cs" Inherits="DailyPage" Title="Untitled Page" %>
<%@ OutputCache Location="None" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


    <asp:Panel ID="panel1" runat="server" CssClass="container">
        <div>
            <asp:Button ID="btnStartDaily" runat="server" OnCommand="Daily_Command"
                CommandArgument="start" Text="Start daily" />
            <asp:Button ID="btnEndDaily" runat="server" OnCommand="Daily_Command" CommandArgument="end" Text="End daily" />
        </div>
        <table>
            <tr>
                <td>
                    Start daily</td>
                <td>
                    <asp:Label ID="StartDaily" runat="server" /></td>
            </tr>
            <tr>
                <td>
                    Duration</td>
                <td>
                    <asp:Label ID="DailyCounter" runat="server"/>
                    <asp:HiddenField ID="DailyCounterValue" runat="server"/>
                </td>
            </tr>
            <tr>
                <td>
                    End Daily</td>
                <td>
                    <asp:Label ID="EndDaily" runat="server" /></td>
            </tr>
        </table>
        <br />
        <br />
        <asp:Button ID="btnAddRegister" runat="server" Text="Add Register" OnClick="btnAddRegister_Click" />
        <table class="dailyTable" cellpadding="0" cellspacing="0">
            <asp:MultiView ID="MultiView" runat="server">
                <asp:View ID="View1" runat="server">
                    <tr>
                        <td>
                            Register
                        </td>
                        <td style="text-align: justify">
                            <asp:TextBox ID="RegisterName" runat="server" TextMode="MultiLine" Rows="3" Columns="80"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Register type
                        </td>
                        <td style="text-align: justify">
                            <asp:DropDownList ID="RegisterType" runat="server">
                                <%--<asp:ListItem Value="0" Text="Scheduled"></asp:ListItem>
                                <asp:ListItem Value="1" Text="Not scheduled"></asp:ListItem>
                                <asp:ListItem Value="2" Text="Break"></asp:ListItem>--%>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Task
                        </td>
                        <td style="text-align: justify">
                            <asp:TextBox ID="txtTask" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <asp:Button ID="btnSaveNewRegister" Text="Save" OnClick="btnSaveNewRegister_Click"
                                runat="server" />
                        </td>
                    </tr>
                </asp:View>
                <asp:View ID="View2" runat="server">
                    <tr style="background-color: Navy; color: White; font-weight: bold">
                        <td>
                            Register</td>
                        <td>
                            Start time</td>
                        <td>
                            Offser time</td>
                    </tr>
                    <tr>
                        <td style="text-align: justify">
                            <asp:Label ID="RegisterNameLabel" runat="server" />
                        </td>
                        <td style="text-align: center">
                            <asp:Label ID="StartTime" runat="server" />
                        </td>
                        <td style="text-align: center">
                            <div id="timer" runat="server" />
                        </td>
                    </tr>
                    <tr style="background-color: Navy; color: White; font-weight: bold">
                        <td colspan="3">
                            Problems
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:TextBox Style="width: 80%" ID="Problems" runat="server" TextMode="MultiLine"
                                Rows="4"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:Button ID="btnSaveRegister" OnClick="btnSaveRegister_Click" runat="server" Text="Save" />
                        </td>
                    </tr>
                </asp:View>
            </asp:MultiView><tr>
                <td colspan="3">
                    <asp:ObjectDataSource ID="DailyReportDS" runat="server" 
                        TypeName="DailyReport.Core.Bussines.DailyManager" EnablePaging="False"
                        SortParameterName="sortExpression" SelectMethod="GetDailyRegistersList">
                        <SelectParameters>
                         <asp:SessionParameter Name="userId" SessionField="UserId" Type="Int32" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                    <asp:GridView ID="DailyGrid" DataSourceID="DailyReportDS" runat="server" AutoGenerateColumns = "false"
                     AllowSorting="true">
                     <Columns>
                     <asp:BoundField DataField="Note" HeaderText="Note" ItemStyle-Width="60%" />
                     <asp:TemplateField HeaderText="Type">
                     <ItemTemplate>
                     <%#ConstantsManager.GetInstance().GetTimeRegisterValue((int)DataBinder.Eval(Container.DataItem, "Type"))%>
                     </ItemTemplate>
                     </asp:TemplateField>
                     
                     <asp:TemplateField HeaderText="Start time">
                     <ItemTemplate>
                     <%#string.Format("{0:t} [{0:d}]", DataBinder.Eval(Container.DataItem, "StartTime"))%>
                     </ItemTemplate>
                     </asp:TemplateField>
                     
                     <asp:TemplateField HeaderText="End time">
                     <ItemTemplate>
                     <%#string.Format(new DateFormatProvider(), "{0:t} [{0:d}]", DataBinder.Eval(Container.DataItem, "EndTime"))%>
                     </ItemTemplate>
                     </asp:TemplateField>
                     </Columns>
                    </asp:GridView>
                    &nbsp;
                </td>
            </tr>
        </table>
    </asp:Panel>
          <script>

var stopCounter= 0;



function startTimer(id){
    stopCounter=0;
    counter(id);
}

function stopTheCounter(){
    stopCounter = 1;
    var myElement = document.getElementById('<%=DailyCounterValue.ClientID%>');
    var counterValue = document.getElementById('<%=DailyCounter.ClientID%>');
    myElement.value = counterValue.innerHTML;

}

function counter(id){
    var myElement = document.getElementById(id);
    var time = StringToTime(myElement);
    time++;
    myElement.innerHTML=TimeToString(time);
    if(stopCounter == 0){
        setTimeout("counter('"+id+"')", 1000);
        }
}

function StringToTime(myElement) {
p = myElement.innerHTML.split(":");
var hour= p[0];
var minute= p[1];
var second= p[2];
time = hour*3600+minute*60+second*1;
return time;
}

function TimeToString(time) {
if(time >-1){
    hour = Math.floor(time/3600);
    minute = Math.floor(time/60) % 60;
    second = time % 60;
    t = hour + ":";
    if(minute < 10)
        t += "0";
    t += minute + ":";
    if(second < 10)
        t += "0";
    t += second;
}else
t = "0:00:00";
return t;
}
<%= ExecuteJavaScript %>
        </script>

</asp:Content>

